//
//  HXCategroyTCell.m
//  ZCooking
//
//  Created by 韩旭 on 16/9/5.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXCategroyTCell.h"
#import "HXCollectionViewCell.h"
#import "HX_Macro.h"
#import "HXCategorySmallModel.h"
#import "UIButton+WebCache.h"
@implementation HXCategroyTCell
- (void)setCategroy:(NSMutableArray *)categroy {
    _categroy = categroy;
    [self.imageHeader sd_setImageWithURL:[NSURL URLWithString:self.categroy[0]]];
    [_collectionView reloadData];
}
- (void)setUp {
    self.backView = [[UIView alloc] init];
   _backView.backgroundColor = [UIColor greenColor];
    self.imageHeader = [[UIImageView alloc] init];
    _imageHeader.backgroundColor = [UIColor cyanColor];
    HXFoodViewFlowLayout *layout = [[HXFoodViewFlowLayout alloc] init];
    layout.delegate = self;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_collectionView];
    [_collectionView registerNib:[UINib nibWithNibName:@"HXCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"collectionView"];
    [self.contentView addSubview:_backView];
    [self.backView addSubview:_imageHeader];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _categroy.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HXCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView" forIndexPath:indexPath];
    if (indexPath.row == 0) {
    } else {
        HXCategorySmallModel *model = self.categroy[indexPath.row];
        cell.button.text = model.text;
        cell.backgroundColor = [UIColor colorWithWhite:0.804 alpha:1.000];
    }
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.items(indexPath.row);
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.collectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    self.backView.frame = CGRectMake(5, 0, ((CGRectGetWidth(self.contentView.bounds) - 4 * 5) * 2 / 5), 85);
    _imageHeader.frame = CGRectMake(0, 0, self.backView.HX_width, self.backView.HX_height);
}
@end